<?php

//更新
namespace App\Http\Controllers\Property;

use App\Common\json;
use App\Http\Controllers\Controller;
use App\Libraries\upload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class UpdateController extends Controller{

    public function APP_Update(Request $request){
        if($request ->isMethod('get')) {
            $id          = $request ->input('id');
            $versionCode = $request->input('versionCode');
            $select = DB::table('app_version')->where('id',$id)->get();
            foreach ($select as $value) {
                if ($value->version_code > $versionCode) {
                    $hasUpdate = true;
                } else {
                    $hasUpdate = false;
                }
                if($value->is_force ==0){
                    $isforce    = false;
                }else{
                    $isforce    = true;
                }

                $dd = array(
                    'hasUpdate' => $hasUpdate,
                    'isForce' => $isforce,
                    'versionCode' => $value->version_code,
                    'versionName' => $value->version_name,
                    'updateContent' => $value->update_content,
                    'url' => $value->url,
                    'md5' => $value->md5,
                    'size' => $value->size
                );
            }
            if ($select == true) {
                return json::json('success', '获取APP更新信息成功', $dd);
            } else {
                $arr = (object)array();
                return json::json('failure', '获取APP更新信息失败', $arr);
            }
        }
    }

}
